package com.yenlien.traceyun.control.service.rest;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.control.bean.RestURL;
import com.yenlien.traceyun.control.config.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-06
 * @description:用户中心rest服务
 **/

@Service
public class UserRestService {
    @Autowired
    private RestService restService;


    public Object findByList(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/findByList", param);
    }

    public Object findByAll(String companyId) {
        JSONObject json = new JSONObject();
        json.put("companyId", companyId);
        return restService.postJson(RestURL.USERCENTER + "user/findByCompanyId/", json);
    }

    public Object checkPassword(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/checkPassword", param);
    }

    /**
     * 加载
     *
     * @param id
     * @return
     */
    public JSONObject findById(String id) {
        return restService.getJson(RestURL.USERCENTER + "user/findById/" + id);
    }

    /**
     * 注册
     *
     * @param map
     * @return
     */
    @Log(operation = "用户注册", profession = "新增注册")
    public JSONObject save(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "user/save", map, files);
    }

    @Log(operation = "用户注册", profession = "新增注册")
    public JSONObject save2(Map<String, Object> map) {
        return restService.postJson(RestURL.USERCENTER + "user/save2", map);
    }

    /**
     * 修改
     *
     * @param map
     * @return
     */
    @Log(operation = "用户修改", profession = "新增修改")
    public JSONObject update(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "user/update", map, files);
    }

    @Log(operation = "用户修改", profession = "新增修改")
    public JSONObject update2(Map<String, Object> map) {
        return restService.postJson(RestURL.USERCENTER + "user/update2", map);
    }

    /**
     * 登录
     *
     * @param uid      用户标识
     * @param password 密码
     * @param appid    应用id
     * @return
     */
    public JSONObject login(String uid, String password, String appid) {
        JSONObject userInfo = new JSONObject();
        userInfo.put("uid", uid);
        userInfo.put("password", password);
        userInfo.put("appid", appid);
        JSONObject result = restService.postJson(RestURL.USERCENTER + "user/login", userInfo);
        return result;
    }

    /**
     * 重置密码
     */
    @PostMapping(value = "/resetpassword")
    @Log(operation = "重置密码", profession = "新增重置")
    public Object resetPassword(@RequestBody JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/resetpassword", param);
    }


    @Log(operation = "重置密码", profession = "新增重置")
    public Object changepassword(@RequestBody JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/changepassword", param);
    }


}
